package com.lory.servlet;

import com.lory.pojo.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "userListServlet", value = "/user/list")
public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<User> users = new ArrayList<>();
        users.add(new User(5, "hongqigong", "1", "man"));
        users.add(new User(3, "yangguo", "2", "man"));
        users.add(new User(4, "xiaolongnv", "3", "women"));
        users.add(new User(2, "guojing", "4", "women"));
        users.add(new User(1, "guofurong", "5", "women"));
        request.setAttribute("userList", users);
        response.setContentType("text/html;charset=utf-8");
        request.getRequestDispatcher("/vms/user-list.vm").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
